﻿namespace DetectWebApi.Models.User
{
    /// <summary>
    /// 用户模型助手
    /// </summary>
    public static class UserHelper
    {
        /// <summary>
        /// 创建用户资料文档
        /// </summary>
        /// <param name="user">用户</param>
        /// <returns>用户资料文档</returns>
        public static UserProfileDocument CreateProfileDocument(this UserDocument user) => new UserProfileDocument(user.id);

        /// <summary>
        /// 将查询模式字符串转换为枚举类型
        /// </summary>
        /// <param name="modeStr">查询模式字符串</param>
        /// <returns></returns>
        public static UserQueryMode ToUserQueryMode(this string modeStr)
        {
            var result = modeStr.ToUpper() switch
            {
                "USERNAME" => UserQueryMode.Username,
                "ID" => UserQueryMode.Id,
                "ALL" => UserQueryMode.All,
                "FUZZY_PHONE" => UserQueryMode.FuzzyPhone,
                "FUZZY_DEPARTMENT" => UserQueryMode.FuzzyDepartment,
                "FUZZY_RESPONSIBLE_PROJECT" => UserQueryMode.FuzzyResponsibleProject,
                _ => UserQueryMode.All
            };
            return result;
        }

    }
}
